package com.github.loveshorn;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.util.StringUtils;

import java.io.File;

/**
 * 使用spring cloud启动服务, 使用zuul路由
 * @author ste7en.liu@gmail.com
 * @version 1.0.0
 * @since 2017/7/19
 */
@SpringBootApplication
public class LoveshornServer {


    private static final String CONFIG_PATH = "CONFIG_PATH";

    public static void main(String[] args) {

        String envPath = System.getenv(CONFIG_PATH.toUpperCase());
        if (StringUtils.isEmpty(envPath)) {
            throw new IllegalStateException(CONFIG_PATH + " is blank");
        }
        if (!envPath.endsWith(File.separator)) {
            envPath = envPath + File.separator;
        }
        String configPath = envPath + "config" + File.separator;
        System.out.println(configPath);
        String logPath = envPath + "log" + File.separator;
        System.setProperty("spring.config.location", configPath);
        System.setProperty("log.base", logPath);
        System.setProperty("log.path", configPath);


        SpringApplication.run(LoveshornServer.class, args);
    }
}
